﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using DAO;
using BUS;

namespace GUI
{
    public partial class frmTheKhachHang : DevComponents.DotNetBar.Office2007Form
    {
        public frmTheKhachHang()
        {
            InitializeComponent();
        }
        KHACHHANG kh = new KHACHHANG();
        public void HienThi()
        {
            kh.MaKH = Int32.Parse(dgvKH.SelectedRows[0].Cells[0].Value.ToString());
            kh.TenKH = dgvKH.SelectedRows[0].Cells[1].Value.ToString();
            kh.SoDienThoai = dgvKH.SelectedRows[0].Cells[2].Value.ToString();
            kh.DiaChi = dgvKH.SelectedRows[0].Cells[3].Value.ToString();
            kh.DiemTichLuy = Convert.ToInt32(dgvKH.SelectedRows[0].Cells[4].Value.ToString());

            txtMaKH.Text = kh.MaKH.ToString();
            txtDiaChi.Text = kh.DiaChi;
            txtTenKH.Text = kh.TenKH;
            txtSDT.Text = kh.SoDienThoai;
            cbbDTL.Text = kh.DiemTichLuy.ToString();

        }
        private void frmTheKhachHang_Load(object sender, EventArgs e)
        {
            cbbDTL.SelectedIndex = 0;
        }

        private void btnLapThe_Click(object sender, EventArgs e)
        {
            kh.TenKH = txtTenKH.Text;
            kh.DiaChi = txtDiaChi.Text;
            kh.SoDienThoai = txtSDT.Text;
            switch (cbbDTL.SelectedIndex)
            {
                case 0:
                    kh.DiemTichLuy = 10;
                    break;
                case 1:
                    kh.DiemTichLuy = 25;
                    break;
                case 2:
                    kh.DiemTichLuy = 40;
                    break;
                case 3:
                    kh.DiemTichLuy = 55;
                    break;
                case 4:
                    kh.DiemTichLuy = 70;
                    break;
                case 5:
                    kh.DiemTichLuy = 90;
                    break;
                default:
                    kh.DiemTichLuy = 120;
                    break;
            }
            KhachHangBUS.ThemKhachHang(kh);
            dgvKH.DataSource = KhachHangBUS.layDSKH();
        }

        private void btnCapNhat_Click(object sender, EventArgs e)
        {
            kh.TenKH = txtTenKH.Text;
            kh.DiaChi = txtDiaChi.Text;
            kh.SoDienThoai = txtSDT.Text;
            switch (cbbDTL.SelectedIndex)
            {
                case 0:
                    kh.DiemTichLuy = 10;
                    break;
                case 1:
                    kh.DiemTichLuy = 25;
                    break;
                case 2:
                    kh.DiemTichLuy = 40;
                    break;
                case 3:
                    kh.DiemTichLuy = 55;
                    break;
                case 4:
                    kh.DiemTichLuy = 70;
                    break;
                case 5:
                    kh.DiemTichLuy = 90;
                    break;
                default:
                    kh.DiemTichLuy = 120;
                    break;
            }
            KhachHangBUS.CapNhatKhachHang(kh);
            dgvKH.DataSource = KhachHangBUS.layDSKH();
        }

        private void dgvKH_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            HienThi();
        }

        private void dgvKH_KeyDown(object sender, KeyEventArgs e)
        {
            HienThi();
        }

        private void dgvKH_KeyUp(object sender, KeyEventArgs e)
        {
            HienThi();
        }

    }
}
